package service.system.impl;

import model.security.UsrRes;
import model.security.UsrAuth;
import model.security.UsrRole;
import model.security.UsrUser;
import model.security.UsrUserRole;
import dao.security.UsrAuthDao;
import dao.security.UsrResDao;
import dao.security.UsrRoleDao;
import dao.security.UsrUserDao;
import dao.security.UsrUserRoleDao;
import service.system.SystemUsraddService;
import util.Time;



public class SystemUsraddServiceImpl implements SystemUsraddService{
	private UsrUserDao userDao;
	private UsrRoleDao roleDao;
	private UsrResDao resDao;
	private UsrAuthDao authDao;
	
	private UsrUserRoleDao userRoleDao;
	
	@Override
	public boolean addRes(UsrRes res){
		resDao.save(res);
		return true;
	}
	
	@Override
	public boolean addRole(UsrRole role){
		roleDao.save(role);
		return true;
	}
	
	@Override
	public String addUser(UsrUser user){
		if(userDao.findOne("useraccount", user.getUseraccount())!=null){
			return "用户账户已存在，请重新添加。";
		}
		
		userDao.save(user);
			
		//保存用户权限
 		/*UsrUser userbean=userDao.findOne("userid",user.getUserid()); 		
 		UsrRole rolebean=roleDao.findOne("roleid",roleid);
 		
 		UsrUserRole a=new UsrUserRole();
 		a.setEnabled(true);
 		a.setCreatetime(Time.CurrentTimestamp());
 		a.setUsrRole(rolebean);
 		a.setUsrUser(userbean);
		
 		userRoleDao.save(a);*/
 		
		return "TRUE";
	}
	
	@Override
	public boolean addAuth(UsrAuth auth){
		authDao.save(auth);
		return true;
	}

	public UsrUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UsrUserDao userDao) {
		this.userDao = userDao;
	}

	public UsrRoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(UsrRoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public UsrResDao getResDao() {
		return resDao;
	}

	public void setResDao(UsrResDao resDao) {
		this.resDao = resDao;
	}

	public UsrAuthDao getAuthDao() {
		return authDao;
	}

	public void setAuthDao(UsrAuthDao authDao) {
		this.authDao = authDao;
	}

	public UsrUserRoleDao getUserRoleDao() {
		return userRoleDao;
	}

	public void setUserRoleDao(UsrUserRoleDao userRoleDao) {
		this.userRoleDao = userRoleDao;
	}
}
